<?php

if(!isset($_SESSION['agency'])) {
	$company = "Persofolio";
} else {
	$company = $_SESSION['agency'];
}

//$q = mysql_query("SELECT users.fname, users.lname, cal.model_name, cal.date, cal.assignment FROM cal INNER JOIN users ON cal.id_users = users.id;");

//$row = mysql_fetch_array($sql);

//$row = mysql_fetch_object($result);


/*$date = $result->date;
$model = $result->model_name;
$assignment = $result->assignment;

$caldate = explode("-", $date);*/

//$q = "SELECT users.fname, users.lname, cal.model_name, cal.date, cal.assignment FROM cal INNER JOIN users ON cal.id_users = users.id;";

//$result = mysql_fetch_object($sql);
//$result = mysql_query($q);
/*
echo "<pre>";
	print_r($event);
	//print_r(explode("-", $result->date));
echo "</pre>";
*/

//$date = array();

$q = $db->query("SELECT users.fname, users.lname, cal.model_name, cal.assignment, cal.date 
FROM users 
INNER JOIN cal 
ON cal.id_users = users.id
");

$q->setFetchMode(PDO::FETCH_ASSOC);


include('mini_cal2.php'); 


?>
<div id="sidebar_wrapper">
	
	<div id="agency_user_container">
		<div id="agency_name">
			<span><?php echo $_SESSION['position']; ?> for <?php if(!isset($company) || $company == "") { echo "Persofolio"; } else { echo $company; } ?></span>
		</div>
		
		<div id="agent_name">
			<span><?php echo "Hello, " . $_SESSION['fname'] . " " . $_SESSION['lname']; ?></span> (<a href="<?php echo $base_url; ?>logout.php">logout</a>)
		</div>
	</div>
	
	<div id="sidebar">
		<ul>
			<?php if(!in_array("agency_calendar", $url_split)) : ?>
					
				<li class="top_border"><a href="<?php echo $base_url; ?>agency_calendar/wschedule.php">Agency Calendar</a>					
				
			<?php else : ?>	
				
				<li class="top_border"><b>Agency Calendar</b>	
					
			<?php endif; ?>
			
			<img id="ac_plus" src="<?php echo $base_url; ?>images/plus.png" width="16" height="16" alt="add event" />
			
			<?php
				
				while($row = $q->fetch()) {

					if($row['fname'] == $_SESSION['fname'] && $row['lname'] == $_SESSION['lname']) {

						//clean out results, avoid duplicates in array
						$cleanrow = array_unique($row);

						/*$date[] = $row['date'];
						$assignment[] = $row['assignment'];
						$model_name[] = $row['model_name'];*/

						$d = explode("-", $row['date']);
						#$date[0] = Y (4-digit)
						#$date[1] = M (2-digit)
						#$date[2] = D (2-digit)
						
						/*$year = date("Y", $row['date']);
						$month = date("n", $row['date']);
						$day = date("j", $row['date']);*/
						
						$year = $d[0];
						$month = $d[1];
						$day = $d[2];
						
						/*$date = array(
							'year' => date("Y", $row['date']),
							'month' => date("n", $row['date']),
							'day' => date("j", $row['date'])
						);*/
						
						/*$date = array(
							'year' => $d[0],
							'month' => $d[1],
							'day' => $d[2]
						);*/
						
						//print_r($row['date']);
						
						
						//begin the mini calendar w/ color codes for agency calendar
						if($row['assignment'] == FALSE) {

							//show nothing if nothing was found..

						} elseif($row['assignment'] == "Option") {

							$cal->setEvent($year, $month, $day, "option_mini");

						} elseif($row['assignment'] == "Job") {

							//$myurl = "<a title='{$row['assignment']} - {$row['model_name']}' href='#'></a>";
							$myurl = "#";

							$cal->setEvent($year, $month, $day, "job_mini");

						} elseif($row['assignment'] == "GoSee") {

							$cal->setEvent($year, $month, $day, "gosee_mini");

						} elseif($row['assignment'] == "Runway") { 

							$cal->setEvent($year, $month, $day, "runway_mini");

						} elseif($row['assignment'] == "Fitting") {

							$cal->setEvent($year, $month, $day, "fitting_mini");

						} elseif($row['assignment'] == "Casting") {

							$cal->setEvent($year, $month, $day, "casting_mini");

						} elseif($row['assignment'] == "Appointment") {

							$myurl = "#";

							$cal->setEvent($year, $month, $day, "appointment_mini", $myurl);

						}

						/*echo "<pre>";
							print_r($date);
						echo "</pre>";*/

						//echo $row['date'] . "<br />";
						/*echo "<pre>";
							var_dump($d);
						echo "</pre>";*/

					} //end if	

				} //endwhile
				
				/*$cal->setEvent("2011","12","17","event"); // create a class="event"
				$cal->setEvent("2011","12","7", "event"); // create a class="event" (default) */
				//$cal->setEvent("2011","12","20","event",$myurl); // create a class="event" and an <a href="this_page.php">
				print $cal->showMonth(true);
			?>
			
			</li>
			
			<li>Agency Persofolio Mail</li>
			<?php if(!in_array("atb", $url_split)) : ?>
				<li><a href="<?php echo $base_url; ?>atb/satb.php">Agency Talent Book Center</a></li>
			<?php else : ?>
				<li><b>Agency Talent Book Center</b>
					<div class="side_sub_menu">
						<p>Talent Book Management</p>
						<?php if(!in_array("satb.php", $url_split)) : ?>
						<p>Send A Talent Book</p>
						<?php else : ?>
						<p><b>Send A Talent Book</b></p>
						<?php endif; ?>
					</div>
				</li>
			<?php endif; ?>
			<li>Agency Account Manager</li>
			<li>Agency Contacts</li>
			<li>Smart Scout&#8482;</li>
			<li>Documents</li>
			<li>My Personal Space</li>
		</ul>
	</div>
</div> <!-- end sidebar_wrapper -->